package com.seckill.order.config;

import com.alibaba.fastjson.JSON;
import com.seckill.order.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;

import java.io.IOException;
import java.util.Map;

/**
 * @program: seckill-parent
 * @description: 监听kafka队列, 达到效果
 * @author: zhanghz001
 * @create: 2021-07-01 14:35
 **/
// @Component
public class ZhzKafkaOrderListener {
    
    @Autowired
    private OrderService orderService;
    
    /**
     * 监听队列
     */
    @KafkaListener(topics = {"neworder"})
    public void receive(String message) {
        //消息转换成map
        Map<String, String> map = JSON.parseObject(message, Map.class);
        //创建订单
        try {
            orderService.hotAdd(map);
        } catch (IOException e) {
            System.out.println("创建订单失败");
            e.printStackTrace();
        }
        
    }
}
